/** 移除列表 */
export default class RemoveList {

    /** 移除列表 */
    private removeList: Set<VoidFunction> = new Set();

    /**
     * 新增
     * @param method 要新增的事件
     */
    public Add(method: VoidFunction) {
        const removeMethod = () => {
            method();
            this.removeList.delete(removeMethod);
        };
        this.removeList.add(removeMethod);
        return removeMethod;
    }

    /** 移除 */
    public Remove(): void {
        this.removeList.forEach(remove => { remove(); });
    }

    /** 清空 */
    public Clear(): void {
        this.removeList.clear();
    }
}
